from sskFind import allindex

def ssk2(s, t, n, decay):
    #print "ssk2:", s, t, n
    if min(len(s), len(t)) < n:
        return 0

    if s[-1] == t[-1]:
        return decay * ssk2(s, t[:-1], n, decay) + decay ** 2 * ssk1(s[:-1], t[:-1], n - 1, decay)
    else:
        return decay * ssk2(s, t[:-1], n, decay)

def ssk1(s, t, n, decay):
    #print "ssk1:", s, t, n
    if n == 0:
        return 1

    if min(len(s), len(t)) < n:
        return 0

    return decay  * ssk1(s[:-1], t, n, decay) + ssk2(s, t, n, decay)

def ssk(s, t, n, decay):
    #print "ssk:", s, t, n
    if min(len(s), len(t)) < n:
        return 0
    return ssk(s[:-1], t, n, decay) + sum([decay ** 2 * ssk1(s, t[:j], n - 1, decay) for j in allindex(t, s[-1])])

def callssk(s1, s2, news_data, n, decay):
    return ssk(news_data[s1], news_data[s2], n, decay)



